package com.gpscookie.mobile;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;

import de.enough.polish.ui.Form;
import de.enough.polish.ui.StringItem;
import de.enough.polish.ui.TextField;
import de.enough.polish.util.Locale;
import de.enough.polish.ui.Gauge;

public class OptionScreen extends BasicScreen implements MemoryStore
{
	private TextField txtLat;
	private TextField txtLon;
	private TextField txtUser;
	private TextField txtPwd;
	private TextField txtRate;
	private StringItem labInfo;
	private Command cmdSave;

	private String userdbid = "";
	private String tag = "";
	private String missiondbid = "";
	private String missionuuid = "";
	private String missionsecret = "";
	private String ad = "";	
	
	public OptionScreen(String title, GPSCookie glcl) 
	{
		super(title, glcl);

		//#style textFieldBig
		this.txtUser = new TextField(Locale.get("USER"),"",60,TextField.EMAILADDR);
		this.append(txtUser);
		//#style textFieldBig
		this.txtPwd = new TextField(Locale.get("PWD"),"",10,TextField.PASSWORD);
		this.append(txtPwd);		
		//#style textField
		this.txtLat = new TextField(Locale.get("LAT"),"",10,TextField.DECIMAL);
		this.append(txtLat);
		//#style textField		
		this.txtLon = new TextField(Locale.get("LON"),"",10,TextField.DECIMAL);
		this.append(txtLon);
		//#style textField		
		this.txtRate = new TextField(Locale.get("REFRESHRATE"),"",10,TextField.DECIMAL);
		this.append(txtRate);
		
		//#style infoText
		this.labInfo = new StringItem(Locale.get("STATUS"), Locale.get("READY"));
		this.append(this.labInfo);
		
		this.cmdSave = new Command(Locale.get("SAVE"), Command.SCREEN, 10);
		this.cmdBack = new Command(Locale.get("BACK"), Command.SCREEN, 20);
		this.addCommand(this.cmdSave);
		this.addCommand(this.cmdBack);
		this.setCommandListener(this);
	}
	
	public void setInfo(String info) {
		this.labInfo.setLabel(Locale.get("WARNING"));
		this.labInfo.setText(info);
	}
	
	public void setParent() {
		this.parentScreen = GPSCookie.mainScreen;
	}
	
	public void commandAction(Command arg0, Displayable arg1) {		
		if (arg0 == cmdBack) {
			this.goBack();
		} else if (arg0 == cmdSave) {
		}
	}

	public String getValue(int key, String defaultValue) {
		if (key==RMSStore.USER) {
			return this.txtUser.getText();
		} else if (key==RMSStore.PWD) {
			return this.txtPwd.getText();
		} else if (key==RMSStore.LAT) {
			return this.txtLat.getText();
		} else if (key==RMSStore.LON) {
			return this.txtLon.getText();
		} else if (key==RMSStore.TAG) {
			return this.tag;
		} else if (key==RMSStore.USERDBID) {
			return this.userdbid;
		} else if (key==RMSStore.REFRESHRATE) {
			return this.txtRate.getText();
		} else if (key==RMSStore.MISSIONDBID) {
			return this.missiondbid;
		} else if (key==RMSStore.MISSIONUUID) {
			return this.missionuuid;
		} else if (key==RMSStore.MISSIONSECRET) {
			return this.missionsecret;
		} else if (key==RMSStore.AD) {
			return this.ad;
		}		
		return defaultValue;
	}

	public void setValue(int key, String value) {
		if (key==RMSStore.USER) {
			this.txtUser.setText(value);
		} else if (key==RMSStore.PWD) {
			this.txtPwd.setText(value);
		} else if (key==RMSStore.LAT) {
			this.txtLat.setText(value);
		} else if (key==RMSStore.LON) {
			this.txtLon.setText(value);
		} else if (key==RMSStore.TAG) {
			this.tag = value;
		} else if (key==RMSStore.USERDBID) {
			this.userdbid = value;
		} else if (key==RMSStore.REFRESHRATE) {
			this.txtRate.setText(value);
		} else if (key==RMSStore.MISSIONDBID) {
			this.missiondbid = value;
		} else if (key==RMSStore.MISSIONUUID) {
			this.missionuuid = value;
		} else if (key==RMSStore.MISSIONSECRET) {
			this.missionsecret = value;
		} else if (key==RMSStore.AD) {
			this.ad = value;
		}		
	}	
}
